<?php

namespace App\Http\Controllers\Common;

use App\Http\Classes\Word;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class WordController extends Controller
{
    /*
     * 获取某一课程下的所有单词
     * GET
     * lesson(int)
     */
    public function getWordsByLesson(Request $request)
    {
        try
        {
            if ( $request->has('lesson') )
            {
                $lesson = $request->get('lesson');

                $word = new Word();
                $words = $word->getWordsByLessonId($lesson);

                if ( $words )
                {
                    return $this->response(1, '获取成功', $words);
                }
                else
                {
                    return $this->response(0, '无匹配数据', null, $word->getMessage());
                }
            }
            else
            {
                return $this->response(0, '缺省参数', null);
            }
        }
        catch (\Exception $exception)
        {
            return $this->exceptionResponse($exception, __FUNCTION__);
        }
    }
}
